#include "Game.h"
#include "Player.h"

Game::Game(sf::RenderWindow* window): window(window)
{
}

void Game::start()
{
	Player player;
	//Load a tile
	sf::Texture block;
	block.loadFromFile("Assets/Block.png");
	Tile *tile;
	tile = new Tile(block);

	sf::Clock clock;
	while(window->isOpen()) 
	{
		sf::Event event; //check window events
		while (window->pollEvent(event))
		{
			switch (event.type){

				case sf::Event::Closed:
					window->close();
					break;

				//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {}
			
				case sf::Event::KeyPressed:
					if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
						player.startmove(Player::Right);
					
					break;
				//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {}
		
				//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {}
				case sf::Event::KeyReleased:
					if(!sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
						player.stopmove();
				default:
				break;
			}
		}

		sf::Time elapsed = clock.restart();

		//Updates
		player.update(elapsed);

		window->clear(sf::Color(0,0,0));

		//Draws
		window->draw(player);
		tile->drawTile(20,20,window);
		window->display();
	}
}